(function interactive () {
	req ();


	function req (currentPage) {
		var currentPage = currentPage || 1;
		ajax({
			url: 'http://blog.creatshare.com/index.php/page/'+currentPage+'/',
			type: 'GET',
			dataType: 'json',
			data: {type: "json"},
			success: function  (responseText) {
				// try {
					var jsonDate = JSON.parse(responseText);
					changeBlog (jsonDate.allPage, jsonDate.currentPage);
					fillData (jsonDate.data);
					log(jsonDate.data)
				   
				// } catch (e) {
				// 	throw new Error("后端传的收据数据有问题")
				// }
			},
			fail: function  (status) {
				console.log(status);
			}
		});
	}

	//改变博文展示
	function changeBlog (allpage, currentPage) {
		var  change = document.getElementById("change");
		if (currentPage < allpage) {
			currentPage += 1;
		} else {
			currentPage = 1;
		}

		log("allpage:"+allpage, "currentPage:"+currentPage);
		change.onclick = function  (e) {
			req(currentPage);
		}
	}

	//填充数据,给我传进来的是json数据
	function fillData (data) {
	    var as = $$(".classify a"),
	        type = $$(".classify span"),
	        time = $$(".classify time"),
	        content = $$(".essay p");

	        log(data);
	  	for (var i = 0, len = as.length; i < len; i++) {
	  		
	  		as[i].innerText =  data[i].title;
	  		
	        as[i].setAttribute("href", data[i].link);

	        type[i].innerText = data[i].cate;

	        time[i].innerText = timeTransform(data[i].created);

	        if (data[i].text != null) {
	        	 content[i].innerText = data[i].text;
	        }
	  	}

	  	function timeTransform (num) {

			//传进来的是秒，解析要是毫秒
			var date = new Date(num*1000);

			// var year = year < 10 ? "0"+year: year;
			return date.getFullYear()+"."+(date.getMonth()+1)+"."+date.getDate();
	 	}
	}
}());


